package edu.szu.huhanpeng.doodlingFight.model.data 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessFriend;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IDisplayData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.ISquareData;
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class ChessData extends DisplayData implements IChessData, IDisplayData
	{
		//使用数字表示棋子的8个方位如下
		//1		2		3
		//4		this	6
		//7		8		9
		public static const ONE:int = 1;
		public static const TWO:int = 2;
		public static const THREE:int = 3;
		public static const FOUR:int = 4;
		public static const SIX:int = 6;
		public static const SEVEN:int = 7;
		public static const EIGHT:int = 8;
		public static const NINE:int = 9;
		
		private static const TEN:int = 10;
		
		public static function opposite(value:int):int
		{
			if ( value > 9 || value < 1 ) 
			{
				if (GlobalConst.setting.DEBUG) 
				{
					throw new Error("body类型出错");
				}
				return -1;
			}
			return TEN - value;
		}
		
		
		private static const CHESS:String = "chess";
		
		
		private static var id:int = 0;
		
		//private var _row:int;		//棋子在棋盘上的 行数， -1则不在棋盘上
		//private var _column:int;	//棋子在棋盘上的 列数， -1则不在棋盘上
		//private var _index:int;		//棋子在棋盘上的 编号（同方格）， -1则不在棋盘上
		private var _square:ISquareData;//棋子所在的方格
		
		private var _type:int;
		
		private var _friend:Vector.<IChessData>; //棋子周围的同类型棋子的引用, 同类的数量
		
		public function get type():int
		{
			return _type;
		}
		
		public function set type(value:int):void
		{
			_type = value;
		}
		
		//public function get row():int 
		//{
			//return _row;
		//}
		//
		//public function set row(value:int):void 
		//{
			//_row = value;
		//}
		//
		//public function get column():int 
		//{
			//return _column;
		//}
		//
		//public function set column(value:int):void 
		//{
			//_column = value;
		//}
		
		public function get friend():Vector.<IChessData>
		{
			return _friend;
		}
		
		public function set friend(value:Vector.<IChessData>):void
		{
			_friend = value;
		}
		
		//public function get index():int 
		//{
			//return _index;
		//}
		//
		//public function set index(value:int):void 
		//{
			//_index = value;
		//}
		
		public function get square():ISquareData 
		{
			return _square;
		}
		
		public function set square(value:ISquareData):void 
		{
			_square = value;
		}
		
		public function ChessData() 
		{
			name = CHESS.concat(id.toString());
			id++;
			
			resetFriend();
		}
		
		
		
		public function updatePosData(row:int, column:int):void
		{
			x = GlobalConst.setting.LU_POINT.x + GlobalConst.setting.CHESS_SIZE * (column + 0.5) + GlobalConst.setting.OFFSET * column;
			y = GlobalConst.setting.LU_POINT.y + GlobalConst.setting.CHESS_SIZE * (row + 0.5) + GlobalConst.setting.OFFSET * row;
		}
		
		public function resetFriend():void
		{
			_friend = new Vector.<IChessData>(10,true);
		}
		
	}

}